<!DOCTYPE html>
<html>
<head>
	<meta charset='utf-8' />
	<title>对象和继承</title>
</head>
<body>
	<script type="text/javascript">
	//原生模式
		function Person () {}
		Person.prototype = {
			constructor: Person,
			name: "vicky",
			age: 24,
			job: "student",
			sayName: function (){
				console.log(this.name);
			}
		}
		var friend = new Person();
		friend.sayName();

	//原型链实现继承
		function SuperType () {
			this.value = "super";
			this.array = [1,2,3];
		}
		SuperType.prototype.getSuperValue = function () {
			return this.value;
		};

		function SubType () {
			this.subValue = "sub";
		}
		SubType.prototype = new SuperType ();//继承父类
		SubType.prototype.getSubValue = function () {
			return this.subValue;
		}
		var instance1 = new SubType();
		var instance2 = new SubType();
		instance1.array.push(4);
		// console.log(instance1.array);
		// console.log(instance2.array);
		// console.log(instance1.getSubValue());
		// console.log(instance1.getSuperValue());

	//借用构造函数实现继承
		function Father () {
			this.array = [1,2,3];
		}
		function Son () {
			Father.call(this);
		}
		var instance = new Son();
		instance.array.push(5);
		var instance3 = new Son();
		// console.log(instance.array);//[1,2,3,5]
		// console.log(instance3.array);//[1,2,3]
	//组合继承
		function Super (name) {
			this.name = name;
			this.array = [1,2,3];
		}
		Super.prototype.sayName = function () {
			console.log(this.name);
		};
		function Sub (name,age) {
			Super.call(this,name);
			this.age = age;
		}
		Sub.prototype = new Super();
		Sub.prototype.constructor = Sub();
		Sub.prototype.sayAge = function () {
			console.log(this.age);
		};
		var a = new Sub("vicky",20);
		a.array.pop(1);
		a.sayName();
		a.sayAge();
		var b = new Sub("jay",37);
		console.log(b.array);
		console.log(a.array);

	function DOG(name){
　　　　this.name = name;
　　　　this.species = '犬科';
　　}
	var dogA = new DOG('大毛');
　　var dogB = new DOG('二毛');
	dogA.species = '猫科';
　　//alert(dogA.species); // 显示"犬科"，不受dogA的影响

	var Chinese = {
　　　　nation:'中国'
　　};
	function object (o) {
		function F() {}
		F.prototype = o;
		return new F();
	}

	var Student = object(Chinese);
	Student.job = "xuesheng";
	alert(Student.nation);





		
	</script>
</body>
</html>